# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: http://doc.scrapy.org/en/latest/topics/item-pipeline.html
import codecs

from scrapy.exceptions import DropItem


class TutorialPipeline(object):

    def __init__(self):
        self.file = codecs.open('items.json', 'w+', encoding='utf-8')
        self.ids_list = list()

    def process_item(self, item, spider):
        # if(item['title']) in self.ids_list:
        #     raise DropItem("Duplicate item found: %s" % item)
        # else:
            # self.ids_list.append(item['title'])
        self.file.write(str(item).encode('utf-8'))
        return item
